// 抽象类Item
abstract class Item {
    abstract void borrow();//借出图书

    abstract void returnItem();//归还图书

    abstract Item getItemDetails();//显示详细信息

    // final方法，返回物品的唯一标识符，子类不能重写
    final String getIdentifier() {
        return "This is a generic identifier";
    }
}

//可预约的物品，接口Reservable
interface Reservable {
    void reserve();
}

// Book类，继承自Item类
class Book extends Item {
    private String title;
    private String author;
    private String isbn;

    //构造函数，调用父类构造函数
    public Book(String title, String author, String isbn) {
        super();
        this.title = title;
        this.author = author;
        this.isbn = isbn;
    }

    @Override
    void borrow() {
        System.out.println("书：“" + title + "”已被借出");
    }

    @Override
    void returnItem() {
        System.out.println("书：“" + title + "”已被归还");
    }

    @Override
    Book getItemDetails() {
        return this;
    }

    public String getTitle() {
        return title;
    }//书名

    public String getAuthor() {
        return author;
    }//作者

    public String getIsbn() {
        return isbn;
    }//ISBN
}

// Magazine类，继承自Item类
class Magazine extends Item {
    private String magazineName;
    private String issueNumber;
    private String publicationDate;

    //构造函数，调用父类构造函数
    public Magazine(String magazineName, String issueNumber, String publicationDate) {
        super();
        this.magazineName = magazineName;
        this.issueNumber = issueNumber;
        this.publicationDate = publicationDate;
    }

    @Override
    void borrow() {
        System.out.println("杂志：“" + magazineName + "”已被借出");
    }

    @Override
    void returnItem() {
        System.out.println("杂志：“" + magazineName + "”已被归还");
    }

    @Override
    Magazine getItemDetails() {
        return this;
    }

    //可被子类重写
    public String getPublicationDate() {
        return publicationDate;
    }//出版日期

    public String getMagazineName() {
        return magazineName;
    }//刊名

    public String getIssueNumber() {
        return issueNumber;
    }//期号
}

// 测试类
class LibraryTest {
    public static void processItem(Item item) {
        item.borrow();
        item.returnItem();
        Item details = item.getItemDetails();
        if (details instanceof Book) {
            Book book = (Book) details;
            System.out.println("书目详细信息：书名：" + book.getTitle() + ",作者：" + book.getAuthor() + ",ISBN版号： " + book.getIsbn());
        } else if (details instanceof Magazine) {
            Magazine magazine = (Magazine) details;
            System.out.println("杂志详细信息：书名：" + magazine.getMagazineName() + ",期刊期号：" + magazine.getIssueNumber() + ",出版日期：" + magazine.getPublicationDate());
        }
    }

    public static void main(String[] args) {
        // 创建Book对象
        Book book = new Book("Name1", "我", "11112222");
        processItem(book);

        // 创建Magazine对象
        Magazine magazine = new Magazine("Name2", "10（2）", "2024.11.11");
        processItem(magazine);
    }
}